<template>
  <div class="app-container">
    景区列表

    <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="hotelQuery.name" placeholder="用户名sd" />
      </el-form-item>
      <el-form-item>
        <el-input v-model="hotelQuery.userStatus" placeholder="用户状态" />
      </el-form-item>

      <!-- <el-form-item>
        <el-select
          v-model="teacherQuery.level"
          clearable
          placeholder="讲师头衔"
        >
          <el-option :value="1" label="高级讲师" />
          <el-option :value="2" label="首席讲师" />
        </el-select>
      </el-form-item> -->

      <el-form-item label="注册时间">
        <el-date-picker
          v-model="hotelQuery.begin"
          type="datetime"
          placeholder="选择开始时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="hotelQuery.end"
          type="datetime"
          placeholder="选择截止时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />
      </el-form-item>

      <el-button
        type="primary"
        icon="el-icon-search"
        @click="getUserPageQuery()"
        >查询</el-button
      >
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>
    <!-- 表格 -->
    <!-- :data是表示绑定data这个数据 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="数据加载中"
      border
      fit
      highlight-current-row
    >
      <el-table-column label="序号" width="70" align="center">
        <template slot-scope="scope">
          {{ (current - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

       <el-table-column prop="hName" label="酒店名" width="200" >
          <template slot-scope="scope">
              <keep-alive>
                <span
                  class="goDetail"
                  v-hasPermi="['station:detail']"
                  @click="go2Detail(scope.row.hId)"
                >
                  {{ scope.row.hName }}
                </span>
              </keep-alive>
            </template>
      </el-table-column>

      <!-- <el-table-column prop="hName" label="酒店名" width="200" /> -->

      <!-- <el-table-column label="头衔" width="80">
        <template slot-scope="scope">
          {{ scope.row.level === 1 ? "高级讲师" : "首席讲师" }}
        </template>
      </el-table-column> -->

      <el-table-column prop="hCity" label="所在城市" width="130" />

      <el-table-column prop="hPrice" label="价格" width="130" />

      <el-table-column prop="hType" label="酒店类型" width="200" />


<el-table-column prop="hImgs" label="酒店图片">
  <template slot-scope="scope">
        <img :src="scope.row.hImgs" :min-width="70" :height="70"/>
      </template>
  </el-table-column>
      <el-table-column prop="hAddress" label="具体地址" width="200" />
<el-table-column prop="hPhone" label="前台电话" width="200" />

<el-table-column prop="startTime" label="开业时间" width="200" />



      <el-table-column
        prop="hDes"
        label="描述"
        width="300"
        :show-overflow-tooltip="true"
      />

      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <!-- vue的执行流程是，通过这里的连接到路由，如何再从路由跳转到页面 -->
          <!-- <router-link :to="'/teacher/edit/' + scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit"
              >修改</el-button
            > -->
          <!-- </router-link> -->
          <el-button
            type="primary"
            size="mini"
            icon="el-icon-edit"
            @click="updateDataById(scope.row.hId)"
            >修改</el-button
          >

          <el-button
            type="danger"
            size="mini"
            icon="el-icon-delete"
            @click="removeDataById(scope.row.hId)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
      :current-page="current"
      :page-size="limit"
      :total="total"
      style="padding: 30px 0; text-align: center"
      layout="total, prev, pager, next, jumper"
      @current-change="getUserPageQuery"
    />
  </div>
</template>
<!-- 在这里写js代码 -->
<script>
import hotel from "@/api/hotel";
export default {
  data() {
    return {
      current: 1, //页码
      limit: 10, //每页多少行
      hotelQuery: {}, //查询条件
      list: [], //列表数据
      total: 1, //总记录数
    };
  },
  created() {
    this.getUserPageQuery();
  },
  methods: {
    //current=1 Es6的新特性，这么写可以保证调用这个方法不传值，他会有一个默认值1
    //为什么会有传值进来，因为我们分页点击上一页或者下一页会调用我们这个方法
    getUserPageQuery(current = 1) {
      //current这个用我们调用这个方法传进来的值
      hotel
        .getHotelPageVo(current, this.limit, this.hotelQuery)
        .then((response) => {
          console.log(response);
          this.list = response.data.list;
          this.total = response.data.total;
        });
    },
    //清空表单
    resetData() {
      this.hotelQuery = {};
      this.getUserPageQuery(id);
    },
    //根据id删除
    removeDataById(id) {
      this.$confirm("此操作将永久删除该讲师, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          hotel.delHotelById(id).then((response) => {
            if (response.code === 20000) {
              //删除成功
              console.log("删除成功");
              //刷新页面
              this.getUserPageQuery();
              this.$message({
                type: "success",
                message: "删除成功!",
              });
            } else {
              console.log("删除失败");
              this.$message({
                type: "error",
                message: "删除失败!",
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //根据id查询酒店订单
    getOrderHotelInfo(id) {
      //路由跳转
      this.$router.push({ path: "/order/hotel/" + id });
    },
    //根据id查询景区订单
    getOrderSceneryInfo(id) {
      //路由跳转,带id
      this.$router.push({ path: "/order/scenery/" + id });
    },

    //数据回显
    updateDataById(id) {
      //路由跳转
      this.$router.push({ path: "/hotel/edit/" + id });
    },
    go2Detail(id) {
      this.$router.push({
        path: "/hotel/edit/"+ id,
      });
    },
  },
};
</script>